package com.fjnu.dao.impl;

import com.fjnu.dao.CategoryDao;
import com.fjnu.entity.Category;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Service;

@Repository
public class CategoryDaoImpl implements CategoryDao {
    @Autowired
    private JdbcTemplate jdbcTemplate;
    @Override
    public int insert(Category category) {
        String sql = "INSERT INTO tb_category (name,order,parent_id,create_time,update_time) VALUES (?,?,?,?,?)";
        int result = jdbcTemplate.update(sql,
                category.getName(),
                category.getOrder(),
                category.getParentId(),
                category.getCreateTime(),
                category.getUpdateTime());
        return result > 0 ? 1 : 0;
    }

    @Override
    public int delete(Integer categoryId) {
        String sql = "DELETE FROM tb_category WHERE id = ?";
        int result = jdbcTemplate.update(sql, categoryId);
        return result > 0 ? 1 : 0;
    }
}
